package com.guijianpan.demo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.guijianpan.demo.domain.Demo;
import com.guijianpan.demo.repository.DemoRepository;
import com.guijianpan.demo.repository.DemoSQLRepository;
import com.guijianpan.demo.repository.specifications.DemoSpecs;

@Service
public class DemoService {
	
	@Autowired
	private DemoRepository demoRepository;
	
	@Autowired
	private DemoSQLRepository demoSQLRepository;

	@Transactional
	public Demo save(Demo demo) {
		return demoRepository.save(demo);
	}

	@Transactional
	public List<Demo> findAll() {
		return (List<Demo>) demoRepository.findAll();
	}

	@Transactional
	public int updateNameById(Long id, String name) {
		return demoRepository.updateNameById(id, name);
	}

	@Transactional
	public int del(Long id) {
		return demoRepository.del(id);
	}

	@Transactional
	public Demo findOne(Long id) {
		return demoRepository.findOne(id);
	}

	public List<Demo> findByCondition(Demo demo) {
		return (List<Demo>) demoRepository.findAll(DemoSpecs.equalBalanceAndlikedemoName(demo));
	}

	public Demo findOne4NativeSQLQuery(Long id) {
		return demoSQLRepository.findOne4NativeSQLQuery(id);
	}

}
